#include<iostream>
using namespace std;

int str2in(string code, int in) {
    int res = 0;
    for(int i=0; i<code.length(); i++) {
        if(code[i] >= '0' && code[i] <= '9') {
            res = res * in + (code[i] - '0');
        } else {
            res = res * in + (code[i] - 'A' + 10);
        }
    }
    return res;
}

string out2str(int num, int out) {
    string str = "";
    if(num == 0)    return "0";
    while(num) {
        int t = num % out;
        num /= out;
        if(t>=0 && t<=9)    str.insert(str.begin(), t+'0');
        else    str.insert(str.begin(), t-10+'A');
    }
    return str;
}

int main() {
    int in, out;
    string incode;
    cin >> in >> incode >> out;
    cout << out2str(str2in(incode, in), out) << endl;
    return 0;
} 